/**
 * Created by Administrator on 2018/3/18 0018.
 */

import React from 'react';
import {
    Link,
} from 'react-router-dom'

import TopBar from '../common/topbar';


class OrderDetail extends React.Component {
    constructor(props) {
        super();
        this.state = {
            id: props.match.params.id,
            data: []
        }
    }
    componentDidMount() {
        let myRequest = 'http://localhost:4000/order/detail/?id='+ this.state.id;
        let myInit = {
            method: 'GET',
            mode: 'cors',
            cache: 'default',
            dataType: 'json',
        };
        window.fetch(myRequest, myInit).then((response) => {
            return response.json();
        }).then((json) => {
            this.setState({data: json.data});
        }).catch((err)=>{
            console.log(err);
        })
    }
    onShare(){
        console.log('测试');
    }
    render(){
        let d = this.state.data||{};
        return (
            <div>
                <TopBar data={this.props} title="订单详情"/>
                <div className="payOrderBox">
                    <div className="base">
                        <img src={decodeURIComponent(d.p_cover)} alt=""/>
                        <div className="title">{decodeURIComponent(d.p_title)}</div>
                        <div>份　　数：{d.o_copies}</div>
                    </div>
                    <ul>
                        <li>优惠　券：{d.o_coupon}</li>
                        <li className="price">订单价格：{d.o_price}</li>
                    </ul>
                    <ul>
                        <li>支付状态：已支付</li>
                        <li>支付方式：支付宝</li>
                        <li>支付金额：{d.o_price}</li>
                        <li>支付时间：2018年3月19日16:33:40</li>
                    </ul>
                    <div className="ctrl">
                        <Link to={'/product/'+d.p_id} className="a1" >再来一份</Link>
                        <a onClick={this.onShare.bind(this)} >分享</a>
                    </div>
                </div>
            </div>
        )
    }
}



export default OrderDetail;
